//===----------------------------------------------------------------------===//
//
// This source file is part of the Soto for AWS open source project
//
// Copyright (c) 2017-2021 the Soto project authors
// Licensed under Apache License v2.0
//
// See LICENSE.txt for license information
// See CONTRIBUTORS.txt for the list of Soto project authors
//
// SPDX-License-Identifier: Apache-2.0
//
//===----------------------------------------------------------------------===//

// THIS FILE IS AUTOMATICALLY GENERATED by https://github.com/soto-project/soto/tree/main/CodeGenerator. DO NOT EDIT.

import SotoCore

/// Error enum for Batch
public struct BatchErrorType: AWSErrorType {
    enum Code: String {
        case clientException = "ClientException"
        case serverException = "ServerException"
    }

    private let error: Code
    public let context: AWSErrorContext?

    /// initialize Batch
    public init?(errorCode: String, context: AWSErrorContext) {
        guard let error = Code(rawValue: errorCode) else { return nil }
        self.error = error
        self.context = context
    }

    internal init(_ error: Code) {
        self.error = error
        self.context = nil
    }

    /// return error code string
    public var errorCode: String { self.error.rawValue }

    /// These errors are usually caused by a client action, such as using an action or resource on behalf of a user that doesn't have permissions to use the action or resource, or specifying an identifier that's not valid.
    public static var clientException: Self { .init(.clientException) }
    /// These errors are usually caused by a server issue.
    public static var serverException: Self { .init(.serverException) }
}

extension BatchErrorType: Equatable {
    public static func == (lhs: BatchErrorType, rhs: BatchErrorType) -> Bool {
        lhs.error == rhs.error
    }
}

extension BatchErrorType: CustomStringConvertible {
    public var description: String {
        return "\(self.error.rawValue): \(self.message ?? "")"
    }
}
